package com.example.hp.yuejian5.model;



import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.RegisterBean;
import com.example.hp.yuejian5.bean.UserBean;
import com.example.hp.yuejian5.service.MyService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.hp.yuejian5.other.url.INDEXURL;

public class MyModel {
    private Retrofit retrofit;
    private MyService myService;


    public MyModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(INDEXURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        myService=retrofit.create(MyService.class);
    }
    public void myInfo(String user_id , final RetrofitListener listener)
    {
        Call<UserBean> call=myService.getMe(user_id);
        call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    public void MineEdit(String user_id,String user_name ,String user_password,String user_tel,String user_gender,String user_email, final RetrofitListener listener){
        Call<RegisterBean> call =myService.updateMy(user_id,user_name,user_password,user_tel,user_gender,user_email);
        call.enqueue(new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {listener.onFail();

            }
        });
    }
}
